package TailRecusion;

public class TailTest {

    public static TailRecursion<Long> factorialTailRecursion(final long factorial, final long number) {
        TailInvoke tailInvoke = new TailInvoke();
        if (number == 1)
            return tailInvoke.done(factorial);
        else
            return tailInvoke.call(() -> factorialTailRecursion(factorial + number, number - 1));
    }

    public static long factorial(final long number) {
        return factorialTailRecursion(1, number).invoke();
    }
    public static void main(String[] args) {

        // 计算阶乘
        factorial(10L);
    }
}
